package com.backend.springboot_project_demo.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private final static int NEGATIVE_ONE = -1;
    private static final int ZERO = 0;
    private int code;
    private String msg;
    private T data;

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Result<T> success() {
        return new Result<T>(ZERO, "Ok");
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(ZERO, "Ok", data);
    }

    public static <T> Result<?> fail() {
        return new Result<>(NEGATIVE_ONE, "服务器理解请求客户端的请求，但是拒绝执行此请求");
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<>(NEGATIVE_ONE, msg);
    }

    public static <T> Result<T> fail(Integer code, String msg) {
        return new Result<>(code, msg);
    }
}
